package com.heatup.apt.management.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.heatup.apt.common.util.JsonTools;
import com.heatup.apt.common.util.RequestTools;
import com.heatup.apt.common.util.ResponseTools;
import com.heatup.apt.management.service.WechatMenuService;
import com.heatup.apt.model.api.ApiResultModel;

/**
 * 用户发给公众号的消息以及开发者需要的事件推送，将被微信转发到该控制器中
 * 
 * @author jixiangyun 2016年11月18日 下午12:03:19
 */
@Controller
@RequestMapping("/wechat_menu")
public class WeChatMsgBackController {
	private static final Logger logger = LoggerFactory.getLogger(WeChatMsgBackController.class);
	
	@Autowired
	private WechatMenuService wechatMenuService;
	
	/**
	 * 生成菜单
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/create_menu")
	public String weChatMsg(HttpServletRequest request, HttpServletResponse response) {
		ApiResultModel<Object> apiResultModel = new ApiResultModel<Object>();
		String callback = RequestTools.RequestString(request, "callback", "");
		apiResultModel.setData(wechatMenuService.createWechatMenu());
		return ResponseTools.CallBackResultJsonP(JsonTools.jsonSer(apiResultModel), callback);
	}
	
	/**
	 * 本地生成线上菜单
	 * @param request
	 * @param response
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/create_menu_real")
	public String weChatMenuReal(HttpServletRequest request,HttpServletResponse response){
		ApiResultModel<Object> apiResultModel = new ApiResultModel<>();
		String callback = RequestTools.RequestString(request, "callback", null);
		apiResultModel.setData(wechatMenuService.createWechatMenuReal());
		return ResponseTools.CallBackResultJsonP(JsonTools.jsonSer(apiResultModel), callback);
	}

}
